package com.maycurobj;

import com.alibaba.fastjson.JSONObject;
import com.maycur.developer.sdk.maycur.ultimate.openapi.request.budget.PostBudgetRequest;
import com.maycur.developer.sdk.maycur.ultimate.openapi.response.budget.PostBudgetResponse;
import com.maycurobj.configuration.CronTask;
import com.maycurobj.service.http.MaycurApiService;
import com.maycurobj.service.impl.*;
import org.apache.commons.codec.digest.DigestUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.text.DecimalFormat;


@SpringBootTest
class MaycurobjApplicationTest3 {
//
    @Autowired
    private MaycurApiService maycurApiService;
    @Autowired
    private MaycurBudgetService maycurBudgetService;
    @Autowired
    private EhrService ehrService;
    @Autowired
    private MaycurService maycurService;
    @Autowired
    private CronTask cronTask;


    @Test
    void contextLoads() {
    }


    @Test
    public void testFindBudget(){
        //            maycurService.getBudget("BU1100","10","2022-06-01",1);
        try {
            PostBudgetRequest req = new PostBudgetRequest();
            req.setOrgBizCode("BU1000");
            req.setSubjectBizCode("07");
            PostBudgetResponse rsp = this.maycurApiService.getMaycurOpenApiClient().execute(req);
            System.out.println("---------"+JSONObject.toJSONString(rsp));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Test
    public void testSetBudget(){
        maycurBudgetService.setOccupyBudget(-200.00,"02","BU1000","forTestOa");
    }

    @Test
    public void testgetEHRUserInfo(){
        String secret = "EC2WZMSAQNVA5W:axxQ2GRNpe52GFWanDCcZ16iKJSOXFNk";
        long timestamp = System.currentTimeMillis();
        String userId = "ZJBS000553";
        String ssoToken = DigestUtils.sha256Hex((secret + ":" + userId + ":" + timestamp).getBytes());
        System.out.println(ssoToken);
    }
    private String format(String code){
        Integer mat = Integer.valueOf(code);
        System.out.println(mat);
        DecimalFormat df1 = new DecimalFormat("00000");
        String encoded = df1.format(mat+1);
        return encoded;
    }
    @Test
    public void test(){
        System.out.println(format("00015"));
    }

    @Test
    public void testgetContractManagementRemind(){
        maycurService.contractManagementRemind();
    }

    @Test
    public void maycurLeave(){

        maycurService.handleEmployeeLeave();
    }

}
